home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1997 February
/
EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso
/
enigma
/
onlypc
/
java
/
samples.bin
/
LoanCalc.java
< prev
next >
Wrap
Text File
|
1996-03-07
|
4KB
|
121 lines
/*
This class is a basic extension of the Frame class. It can be used by
either an applet or application. To use it, create a reference to the class,
instantiate an object of the class, and call the show() method.
example:
LoanCalc myLoanCalc;
myLoanCalc = new LoanCalc();
myLoanCalc.show();
You can add controls or menus to LoanCalc with Cafe Studio.
*/
import java.awt.*;
import java.lang.*;
public class LoanCalc extends Frame {
public LoanCalc() {
super("Loan Calculations");
//{{INIT_CONTROLS
setLayout(null);
addNotify();
resize(insets().left + insets().right + 395, insets().top + insets().bottom + 248);
label1=new Label("Principal =");
add(label1);
label1.reshape(insets().left + 15,insets().top + 33,105,16);
PrincipalField=new TextField(8);
add(PrincipalField);
PrincipalField.reshape(insets().left + 192,insets().top + 29,72,20);
label2=new Label("Interest Rate =");
add(label2);
label2.reshape(insets().left + 15,insets().top + 67,117,18);
InterestRateField=new TextField(8);
add(InterestRateField);
InterestRateField.reshape(insets().left + 192,insets().top + 68,72,18);
label3=new Label("Length of Loan (years) =");
add(label3);
label3.reshape(insets().left + 15,insets().top + 106,159,18);
LengthLoanField=new TextField(8);
add(LengthLoanField);
LengthLoanField.reshape(insets().left + 192,insets().top + 106,72,18);
MonthlyPayField=new TextField(8);
add(MonthlyPayField);
MonthlyPayField.reshape(insets().left + 192,insets().top + 145,72,18);
label4=new Label("Monthly Payment =");
add(label4);
label4.reshape(insets().left + 15,insets().top + 145,141,18);
CalcButton=new Button("Calculate");
add(CalcButton);
CalcButton.reshape(insets().left + 288,insets().top + 102,84,25);
//}}
//{{INIT_MENUS
//}}
MonthlyPayField.setBackground(Color.gray);
PrincipalField.requestFocus();
}
public synchronized void show() {
move(50, 50);
super.show();
}
public boolean handleEvent(Event event) {
if (event.id == Event.ACTION_EVENT && event.target == CalcButton) {
OnCalculateLoan();
return true;
}
else
if (event.id == Event.WINDOW_DESTROY) {
hide();
return true;
}
return super.handleEvent(event);
}
//{{DECLARE_CONTROLS
Label label1;
TextField PrincipalField;
Label label2;
TextField InterestRateField;
Label label3;
TextField LengthLoanField;
TextField MonthlyPayField;
Label label4;
Button CalcButton;
//}}
//{{DECLARE_MENUS
//}}
public void OnCalculateLoan() {
double Principal, InterestRate, LengthLoan, MonthlyPay, IntDec, NumMonths;
try {
Principal = ( Double.valueOf(PrincipalField.getText() ) ).doubleValue();
InterestRate = ( Double.valueOf(InterestRateField.getText()) ).doubleValue();
LengthLoan = ( Double.valueOf(LengthLoanField.getText() ) ).doubleValue();
} catch (NumberFormatException e) {return;}
if (Principal < 0 || InterestRate < 0 || LengthLoan < 0) return;
IntDec = InterestRate / (12.0 * 100.0);
NumMonths = LengthLoan * 12.0;
MonthlyPay = Principal * (IntDec / (1.0 - Math.pow((1.0 + IntDec), -NumMonths)));
MonthlyPayField.setText(String.valueOf(MonthlyPay));
}
}